From 0a38a347b755a496b16302db1bd4469d402894db Mon Sep 17 00:00:00 2001 From: Ewan Mellor Date: Sat, 16 Dec 2006 12:49:23 +0000 Subject: [PATCH] Persist all the Xen-API data values for VMs. Signed-off-by: Ewan Mellor --- tools/python/xen/xend/XendAPI.py | 5 +++- tools/python/xen/xend/XendConfig.py | 35 ++++++++++++++++++------- tools/python/xen/xend/XendDomain.py | 3 ++- tools/python/xen/xend/XendDomainInfo.py | 5 ++-- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/tools/python/xen/xend/XendAPI.py b/tools/python/xen/xend/XendAPI.py index c43ae75976..540ab2e45d 100644 --- a/tools/python/xen/xend/XendAPI.py +++ b/tools/python/xen/xend/XendAPI.py @@ -663,7 +663,10 @@ class XendAPI: XendDomain.instance().get_vm_by_uuid(vm_ref).info[name]) def VM_set(self, name, session, vm_ref, value): - XendDomain.instance().get_vm_by_uuid(vm_ref).info[name] = value + xd = XendDomain.instance() + dominfo = xd.get_vm_by_uuid(vm_ref) + dominfo.info[name] = value + xd.managed_config_save(dominfo) return xen_api_success_void() # attributes (ro) diff --git a/tools/python/xen/xend/XendConfig.py b/tools/python/xen/xend/XendConfig.py index e80422eaaa..113dc4c42c 100644 --- a/tools/python/xen/xend/XendConfig.py +++ b/tools/python/xen/xend/XendConfig.py @@ -430,8 +430,12 @@ class XendConfig(dict): """ cfg = {} - # First step is to convert deprecated options to - # current equivalents. + for key, typ in XENAPI_CFG_TYPES.items(): + val = sxp.child_value(sxp_cfg, key) + if val is not None: + cfg[key] = typ(val) + + # Convert deprecated options to current equivalents. restart = sxp.child_value(sxp_cfg, 'restart') if restart: @@ -576,6 +580,11 @@ class XendConfig(dict): """ cfg = self._parse_sxp(sxp_cfg) + for key, typ in XENAPI_CFG_TYPES.items(): + val = cfg.get(key) + if val is not None: + self[key] = typ(val) + # Convert parameters that can be directly mapped from # the Legacy Config to Xen API Config @@ -590,9 +599,13 @@ class XendConfig(dict): except KeyError: pass - self['PV_bootloader'] = cfg.get('bootloader', '') - self['PV_bootloader_args'] = cfg.get('bootloader_args', '') - + def update_with(n, o): + if not self.get(n): + self[n] = cfg.get(o, '') + + update_with('PV_bootloader', 'bootloader') + update_with('PV_bootloader_args', 'bootloader_args') + image_sxp = sxp.child_value(sxp_cfg, 'image', []) if image_sxp: self.update_with_image_sxp(image_sxp) @@ -760,11 +773,8 @@ class XendConfig(dict): self.validate() - def to_xml(self): - """Return an XML string representing the configuration.""" - pass - - def to_sxp(self, domain = None, ignore_devices = False, ignore = []): + def to_sxp(self, domain = None, ignore_devices = False, ignore = [], + legacy_only = True): """ Get SXP representation of this config object. Incompat: removed store_mfn, console_mfn @@ -785,6 +795,11 @@ class XendConfig(dict): if domain.getDomid() is not None: sxpr.append(['domid', domain.getDomid()]) + if not legacy_only: + for name in XENAPI_CFG_TYPES.keys(): + if name in self and self[name] not in (None, []): + sxpr.append([name, str(self[name])]) + for xenapi, legacy in XENAPI_CFG_TO_LEGACY_CFG.items(): if self.has_key(xenapi) and self[xenapi] not in (None, []): if type(self[xenapi]) == bool: diff --git a/tools/python/xen/xend/XendDomain.py b/tools/python/xen/xend/XendDomain.py index b0a8de6a0a..81c39384d4 100644 --- a/tools/python/xen/xend/XendDomain.py +++ b/tools/python/xen/xend/XendDomain.py @@ -284,7 +284,8 @@ class XendDomain: fd, fn = tempfile.mkstemp() f = os.fdopen(fd, 'w+b') try: - prettyprint(dominfo.sxpr(), f, width = 78) + prettyprint(dominfo.sxpr(legacy_only = False), f, + width = 78) finally: f.close() try: diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index 8b90814db2..27dcce7e71 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -1800,9 +1800,10 @@ class XendDomainInfo: log.trace("XendDomainInfo.update done on domain %s: %s", str(self.domid), self.info) - def sxpr(self, ignore_store = False): + def sxpr(self, ignore_store = False, legacy_only = True): result = self.info.to_sxp(domain = self, - ignore_devices = ignore_store) + ignore_devices = ignore_store, + legacy_only = legacy_only) if not ignore_store and self.dompath: vnc_port = self.readDom('console/vnc-port') -- 2.30.2